import { BadRequestException, PipeTransform } from '@nestjs/common';
import { TaskStatus } from '../task-status.enum';

export class TaskStatusValidationPipe implements PipeTransform {
  readonly validStatus = [
    TaskStatus.DONE,
    TaskStatus.IN_PROGRESS,
    TaskStatus.OPEN,
  ];

  transform(value: any) {
    if (this.isValidStatus(value)) {
      return value;
    }
    throw new BadRequestException(`${value}不是一个正确的参数`);
  }
  private isValidStatus(status: any) {
    if (this.validStatus.includes(status)) {
      return true;
    }
    return false;
  }
}
